-- @owner:魏亚军
-- @date:2023-12-26
-- @testpoint:2.测试在事务中修改序列属主

--step1:创建一个普通序列，属性默认;expect:成功(1 row)
drop user if exists u_opengauss_alter_sequence_owner_case0002;
create user u_opengauss_alter_sequence_owner_case0002 with password 'opengauss@123';
drop sequence if exists seqopengauss_alter_sequence_owner_case0002_1;
create sequence seqopengauss_alter_sequence_owner_case0002_1;

--step2:查看序列当前属主;expect:成功(1 row)
select usename from pg_user where usesysid=(select relowner from pg_class where relname='seqopengauss_alter_sequence_owner_case0002_1');

--step3:修改序列属主为u_opengauss_alter_sequence_owner_case0002;expect:成功
begin
alter sequence seqopengauss_alter_sequence_owner_case0002_1 owner to u_opengauss_alter_sequence_owner_case0002;
end;
/

--step4:查看修改是否生效;expect:成功(1 row)
select usename from pg_user where usesysid=(select relowner from pg_class where relname='seqopengauss_alter_sequence_owner_case0002_1');

--step5:修改序列属主为yat_user;expect:成功
begin;
alter sequence seqopengauss_alter_sequence_owner_case0002_1 owner to yat_user;
--step6:提交事务，并查看修改是否成功;expect:成功
end;
/

--step7:查看修改是否生效;expect:成功(1 row)
select usename from pg_user where usesysid=(select relowner from pg_class where relname='seqopengauss_alter_sequence_owner_case0002_1');

--step8:清理环境:expect:成功(1 row)
drop sequence seqopengauss_alter_sequence_owner_case0002_1;
drop user u_opengauss_alter_sequence_owner_case0002;